/**
 * Created by penghaozhong on 2017/1/15.
 */
app.service('userSession',['$rootScope','$window', function($rootScope,$window) {

    this.create = function (json) {
        if(json != null){
            this.user = angular.fromJson(json);
            $rootScope.userSession = this;
            $window.sessionStorage.removeItem('userSession');
            $window.sessionStorage.setItem("userSession",angular.toJson(this.user));
        }
    };

    this.destroy = function () {
        this.user = null;
    };

    var tmp = $window.sessionStorage.getItem("userSession");
    if(tmp){
        this.create(tmp);
    }

    return this;
}]);


/**
 * post 键值对提交方式
 */
app.service('postCfg', function () {
    var transFn = function (data) {
        return $.param(data);
    };
    var postCfg = {
        headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
        transformRequest: transFn
    };
    return postCfg;
});